'use strict';

/* Controllers */
app.controller('SignupFormController', ['$scope', '$http', '$state', 'apiService','$cookieStore','$timeout', function ($scope, $http, $state, apiService,$cookieStore,$timeout) {
  $scope.user = {};
  $scope.authError = null;
  
  $scope.signup = function () {
    $scope.authError = null;
    $scope.btn_disabled = true;
    // 提交数据
    apiService.post({
      modelName: 'account',
      apiName: 'addAccountDB'
    },$scope.user, function (data) {
      $scope.btn_disabled = false;
      if (data.code == 200) {
        $scope.authError = data['msc'];
        $timeout(function(){
          $state.go('access.signin');
        },1000);
      } else {
        $scope.authError = data['msc'];
      }
    }, function (err) {
      $scope.btn_disabled = false;
      console.log(err);
      $scope.authError = '服务器出小差咯！';
    });

  };
}]);